package com.lsj.controller;

import com.lsj.core.response.CommonResult;
import com.lsj.core.util.ExceptionHelperUtil;
import com.lsj.dto.sys.RoleMenuDto;
import com.lsj.service.RoleMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author:lin.sj
 * @Data:2021/7/8 19:28
 * @Desc: 角色与菜单处理
 */
@RestController
@RequestMapping("/sys_role_menu")
@Api(tags = "角色与菜单处理")
public class RoleMenuController {

    @Autowired
    RoleMenuService roleMenuService;

    @PostMapping("/updateMenuForRole")
    @ApiOperation(value = "更新角色与菜单关系")
    public CommonResult updateMenuForRole(@RequestBody @Validated RoleMenuDto dto){
        roleMenuService.updateMenuForRole(dto);
        return CommonResult.success();
    }

    @GetMapping("/getMenuIdsByRoleId")
    @ApiOperation(value = "根据角色编码查找对应的权限信息")
    public CommonResult getMenuIdsByRoleId(@RequestParam("roleId") Long roleId){
        ExceptionHelperUtil.nullObjException(roleId,"角色Id不能为空");
        List<String> menuIds = roleMenuService.getMenuIdsByRoleId(roleId);
        return CommonResult.success(menuIds);
    }
}
